package com.kaibes.platform.link;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kaibes.web.api.ApiLink;
import com.kaibes.web.api.ResponseApi;

@RestController
@RequestMapping("/links")
public class LinkApi extends ResponseApi<Link, LinkService>{

    @PostMapping
    @ApiLink("创建链接")
    public ResponseEntity<List<Number>> post(@RequestBody LinkPost data) {
        return super.post(data, "创建链接成功", "创建链接失败");
    }
    
    @ApiLink("删除链接，根据id")
    @DeleteMapping
    public ResponseEntity<Object> deleteByIdQuery(@RequestBody List<Short> ids) {
        return super.deleteById(ids, "删除链接成功", "删除链接失败");
    }
    
    @ApiLink("删除链接，根据id")
    @DeleteMapping("/{id:\\d+}")
    public ResponseEntity<Object> deleteByIdQuery(@PathVariable Short id) {
        return super.deleteById(id, "删除链接成功", "删除链接失败");
    }
    
    @PutMapping("/{id:\\d+}")
    @ApiLink("修改链接，根据id")
    public ResponseEntity<Object> putById(@PathVariable Short id, @RequestBody @Validated(PutMapping.class) LinkUpdate data) {
        return super.putById(data, id, "修改链接成功", "修改链接失败");
    }
    
}
